package com.wskh.edu.controller.front;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wskh.commonUtil.R;
import com.wskh.edu.entity.Course;
import com.wskh.edu.entity.Teacher;
import com.wskh.edu.service.CourseService;
import com.wskh.edu.service.TeacherService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@Api(value="讲师前台展示")
@RestController
@RequestMapping("/eduService/teacherFront")
@CrossOrigin
public class TeacherFrontController {

    @Autowired
    TeacherService teacherService;
    @Autowired
    CourseService courseService;

    @GetMapping("getTeacherFrontListByPage/{page}/{limit}")
    public R pageList(
            @ApiParam(name = "page", value = "当前页码", required = true)
            @PathVariable Long page,
            @ApiParam(name = "limit", value = "每页记录数", required = true)
            @PathVariable Long limit){
        Page<Teacher> pageParam = new Page<Teacher>(page, limit);
        Map<String, Object> map = teacherService.getTeacherFrontListByPage(pageParam);
        return R.ok().data(map);
    }

    @ApiOperation(value = "根据ID查询讲师")
    @GetMapping(value = "getTeacherById/{id}")
    public R getTeacherById(
            @ApiParam(name = "id", value = "讲师ID", required = true)
            @PathVariable String id){
        //查询讲师信息
        Teacher teacher = teacherService.getById(id);
        //根据讲师id查询这个讲师的课程列表
        List<Course> courseList = courseService.selectByTeacherId(id);
        return R.ok().data("teacher", teacher).data("courseList", courseList);
    }

}
